﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using School.Entities;
using School.Accounting;

namespace School.Pages.Accounting
{
    public partial class SearchForVouchers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((IQueryable<int>)Session["privilage"] != null)
            {
                var x = (IQueryable<int>)Session["privilage"];

                if (x.Contains(115) == true)
                {

                }
                else
                    Response.Redirect("../organization/no_privelege.aspx");
            }
            else
                Response.Redirect("../organization/no_privelege.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            long voucher = 0;
            long paymentOrder = 0;

            Panel1.Visible = false;
            Label1.Visible = false;

            if (long.TryParse(TxtVoucher.Text, out voucher))
                GridView1.DataSource = Voucher.GetVoucherByNumber(voucher);
            else if (long.TryParse(TxtPaymentOrder.Text, out paymentOrder) && voucher == 0)
                GridView1.DataSource = Voucher.GetVoucherByPaymentOrder(paymentOrder);
            else
                return;

            GridView1.DataBind();

            if (GridView1.Rows.Count > 0)
                Panel1.Visible = true;
            else
                Label1.Visible = true;
        }
    }
}